#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;

const char FILENAME[20] = "MemberAccount.txt";
const int MIN_PASSWORD_LENGTH = 5;
const int MAX_PASSWORD_LENGTH = 15;
const int MIN_POINTS = 0;
const int MAX_POINTS = 99999;
const int MAX_REVIEW = 5;
const int NO_OF_MEMBERS = 1000;
const int NO_OF_HOTELS = 391;
const string NAME[5] = {"Abdulla", "Yu Xiang", "Nas", "Lian Sheng", "Samuel"};
const string TYPE[2] = {"Admin", "Member"};

int main()
{
	fstream file(FILENAME, ios::out);
	
	srand(time(NULL));
	int pwdLen, pwdChar, name, noOfRev, points, type, HIID;
	char pwd[16];
	string revGranted;
	stringstream HI;
	
	for(int i = 1; i <= NO_OF_MEMBERS; i++)
	{
		name = rand() % 5;
		
		srand(rand());
		pwdLen = (rand() % (MAX_PASSWORD_LENGTH - MIN_PASSWORD_LENGTH + 1)) 
						+ MIN_PASSWORD_LENGTH;
		for(int j = 0; j < pwdLen; j++)
		{
			do{
				srand(rand());
				pwdChar = (rand() % 95) + 32;
			}while(pwdChar == 124 || pwdChar == 34);
			pwd[j] = (char)pwdChar;
		}
		pwd[pwdLen] = '\0';		
		
		srand(rand());
		noOfRev = rand() % MAX_REVIEW + 1;
		revGranted = "";
		for(int j = 0; j < noOfRev; j++)
		{
			srand(rand());
			HI.str(string());
			HI << "HI" << setw(5) << setfill('0') << (rand() % NO_OF_HOTELS + 1) + 1;
			revGranted += HI.str();
			if(j < noOfRev-1)
				revGranted += ",";
		}
		srand(rand());
		points = (rand() % MAX_POINTS) + MIN_POINTS;
		
		if(i % 20 == 0)
		{
			srand(rand());		
			type = rand() % 2;
		}
		else
			type = 1;
		
	file << "ID" << setw(5) << setfill('0') << i << "|"
		 << NAME[name] << "|"
		 << pwd << "|"
		 << revGranted << "|"
		 << points << "|"
		 << TYPE[type] << "\n";
	}
}